﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ResUma
{
    public partial class TipSporuriFrm : FrmCard
    {
        public TipSporuriFrm(ModuleClass mc): base(mc)
        {
            InitializeComponent();//
            workConnString = mc.workConnectionString;
            formatTipSporBindingSource.List.Add(new FormatTipSpor("Grila", "G"));
            formatTipSporBindingSource.List.Add(new FormatTipSpor("Procent", "P"));
            formatTipSporBindingSource.List.Add(new FormatTipSpor("Suma", "S"));
            formatTipSporBindingSource.List.Add(new FormatTipSpor("Grila Ocupatie", "F"));
            formatTipSporBindingSource.List.Add(new FormatTipSpor("Grila Ocupatie/Departamente", "D"));

            intraInBindingSource.List.Add(new FormatTipSpor("Salariu de baza", "SB"));
            intraInBindingSource.List.Add(new FormatTipSpor("Inclus in Salariu Grila", "SG"));
            intraInBindingSource.List.Add(new FormatTipSpor("Baza vechime", "BV"));
            intraInBindingSource.List.Add(new FormatTipSpor("Salar functie", "SF"));

            bazaSporBindingSource.List.Add(new FormatTipSpor("Salar Baza", "SB"));
            bazaSporBindingSource.List.Add(new FormatTipSpor("Salar Grila", "SG")); 
            bazaSporBindingSource.List.Add(new FormatTipSpor("Salar", "SI"));
            bazaSporBindingSource.List.Add(new FormatTipSpor("Salar Functie", "SF"));
            bazaSporBindingSource.List.Add(new FormatTipSpor("Baza Vechime", "BV"));


            dataDefinireDTP.Format = DateTimePickerFormat.Custom;
            dataDefinireDTP.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
            HandleRezumat += new EventHandler(TipSporuriFrm_HandleRezumat);
        }

        void TipSporuriFrm_HandleRezumat(object sender, EventArgs e)
        {
            TipSporuriRezFrm frm = new TipSporuriRezFrm(ModuleInfo, tipSporBindingSource);
            frm.MdiParent = this.MdiParent;
            frm.Show();
            _CloseFormList.Add(frm);
        }

        private void TipSporuriFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.tipSporTableAdapter.Connection = con;
            this.tipSporTableAdapter.Fill(this.eSRPDataSet.TipSpor);
            InchideConexiune(con);
            this.listBndSourceMain.Add(tipSporBindingSource);
            listTableAdaptor.Add(tipSporTableAdapter.Adapter);

        }

        private void formatCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (formatCB.SelectedValue == null)
                return;
            GrilaL.Visible = formatCB.SelectedValue.ToString() == "G";
            valoareNUD.Enabled = (formatCB.SelectedValue.ToString()!="G" && formatCB.SelectedValue.ToString()!="F");
            GrileOcupatiiLL.Visible = formatCB.SelectedValue.ToString() == "F";
            GrileOcupatiiDepLL.Visible = formatCB.SelectedValue.ToString() == "D";
        }

        private void GrilaL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (tipSporBindingSource.Current == null)
                return;
            if (((DataRowView)tipSporBindingSource.Current).IsNew)
            {
                MessageBox.Show("Va rugam salvati tipul de spor inainte de a definii grila!");
                return;
            }
            ESRPDataSet.TipSporRow rdsp = ((DataRowView)tipSporBindingSource.Current).Row as ESRPDataSet.TipSporRow;
            GrilaFrm frm = new GrilaFrm(ModuleInfo, rdsp.IdTipSpor);
            frm.ShowDialog();
        }

        private void GrileOcupatiiLL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (tipSporBindingSource.Current == null)
                return;
            if (((DataRowView)tipSporBindingSource.Current).IsNew)
            {
                MessageBox.Show("Va rugam salvati tipul de spor inainte de a definii grila!");
                return;
            }
            ESRPDataSet.TipSporRow rdsp = ((DataRowView)tipSporBindingSource.Current).Row as ESRPDataSet.TipSporRow;
            GrilaOcupatiiFrm frm = new GrilaOcupatiiFrm(ModuleInfo, rdsp.IdTipSpor);
            frm.ShowDialog();
        }

        private void concediuOdihnaCheckBox_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void concediuBoalaCheckBox_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void concediuOreSuplimentareCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            
        }

        private void GrileOcupatiiDepLL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (tipSporBindingSource.Current == null)
                return;
            if (((DataRowView)tipSporBindingSource.Current).IsNew)
            {
                MessageBox.Show("Va rugam salvati tipul de spor inainte de a definii grila!");
                return;
            }
            ESRPDataSet.TipSporRow rdsp = ((DataRowView)tipSporBindingSource.Current).Row as ESRPDataSet.TipSporRow;
            GrilaOcupatiiDepFrm frm = new GrilaOcupatiiDepFrm(ModuleInfo, rdsp.IdTipSpor);
            frm.ShowDialog();
        }
    }

    [Serializable]
    public class FormatTipSpor
    {
        public FormatTipSpor(String nume, String tag)
        {
            _Name = nume;
            _Tag = tag;
        }

        private String _Name = String.Empty;
        [System.ComponentModel.Bindable(true)]
        public String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        private String _Tag = String.Empty;
        [System.ComponentModel.Bindable(true)]
        public String Tag
        {
            get
            {
                return _Tag;
            }
            set
            {
                _Tag = value;
            }
        }
    }
}
